package com.zhu.algorithm.jzOffer.queueAndStack;

import cn.hutool.core.util.ObjectUtil;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zhujiabao
 * @Date: 2023/01/15/11:45
 * @Description:
 * 描述：用两个栈来实现一个队列，使用n个元素来完成 n 次在队列尾部插入整数(push)和n次在队列头部删除整数(pop)的功能。 队列中的元素为int类型。
 * 保证操作合法，即保证pop操作时队列内已有元素。
 *
 * 输入：["PSH1","PSH2","POP","POP"]
 * 返回值：1,2
 */
public class Solution09 {
    private static Map<String, String> linkedHashMap = new LinkedHashMap<>();
    private static Set<String> linkedHashSet = new LinkedHashSet<>();
    private static Map<String, String> treeMap = new TreeMap<>();
    private static Set<String> set = new TreeSet<>();
    private static Map<String, String> hashMap = new HashMap<>();
    private static Map<String, String> hashMaphave = new HashMap(16, (float) 0.7);
    private static Map<String, String> concurrentHashMap = new ConcurrentHashMap();
    private static Set<String> hashSet = new HashSet<>();

    private static ReentrantLock reentrantLock = new ReentrantLock();



    Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();

    public static void main(String[] args) {
        String[] operations = {"PSH1", "PSH2", "POP","PSH3","PSH4","PSH5", "POP", "POP", "POP", "POP"};
        Solution09 solution09 = new Solution09();
        // 识别操作类型，取出操作值
        for (String operation : operations) {
            solution09.handle(operation);
        }

        hashMap.put("zhuzhumen","1");
        hashMap.put("zhuzhumen","2");
        hashMap.get("zhuzhumen");
        linkedHashMap.get("1");
        treeMap.get("1");
    }

    // 识别操作类型，取出操作值
    private void handle(String operation) {
        String operate = operation.substring(0, 3);
        System.out.println(operate);
        if ("PSH".equals(operate)) {
            int node = Integer.parseInt(operation.substring(3));
            push(node);
        } else {
            System.out.println(pop());
        }
    }
    public void push(int node) {
        while (!stack2.isEmpty()) {
            stack1.push(stack2.pop());
        }
        stack1.push(node);
    }

    public int pop() {
        while (!stack1.isEmpty()) {
            stack2.push(stack1.pop());
        }
        return stack2.pop();
    }



}
